﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;
using System.IO;
using KPIS.GERP.GFMS.IBLL;
using KPIS.GERP.GFMS.BLL;
using KPIS.GERP.GFMS.MODEL;

using KPIS.GERP.GFMS.APP.App_UI.Commons;
using KPIS.GERP.GFMS.DAL;

namespace KPIS.GERP.GFMS.APP.App_UI.Forms
{
    public partial class FIM_MAS_Contacts : System.Web.UI.Page
    {
        Main main = new Main();
        IBLL_FIM_MAS_Contacts con = new B_FIM_MAS_Contacts();
        IBLL_HRM_MAS_Districts dis = new B_HRM_MAS_Districts();
        IBLL_HRM_MAS_Amphurs amp = new B_HRM_MAS_Amphurs();
        IBLL_HRM_MAS_Provinces prov = new B_HRM_MAS_Provinces();
        IBLL_HRM_MAS_Countries country = new B_HRM_MAS_Countries();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //======= test only =========
                //Session["EmpSeq"] = "1";
                //===========================

                UpdateUI1("ViewAll");
                //UpdateUI2("ViewAll");
                LoadDDLDistrictSeq();
                LoadRBLContactType();
                //RadGrid2.Enabled = false;
                //PanelControl2.Enabled = false;
            }
        }

        protected void LoadRadGrid1()
        {
            RadGrid1.DataSource = con.GetFull();
        }

        //protected void LoadRadGrid2(string strContactSeq)
        //{
        //    RadGrid2.DataSource = per.GetFull(strContactSeq);
        //    RadGrid2.DataBind();
        //}

        protected void LoadDDLDistrictSeq()
        {
            RadTreeView tree = (RadTreeView)ddlDistrictSeq.Items[0].FindControl("treeDistrictSeq");
            LoadRootNodes(tree, TreeNodeExpandMode.ServerSideCallBack);
        }

        protected void LoadDDLCountrySeq()
        {
            ddlCountrySeq.DataSource = country.GetList();
            ddlCountrySeq.DataBind();
        }

        protected void LoadRBLContactType()
        {
            rblContactType.Items.Clear();
            if (rblContactTypeGroup.SelectedValue == "1")
            {
                rblContactType.Items.Add(new ListItem("ส่วนราชการ", "1"));
                rblContactType.Items.Add(new ListItem("รัฐวิสาหกิจ", "2"));
                rblContactType.Items[0].Selected = true;
            }
            else
            {
                rblContactType.Items.Add(new ListItem("นิติบุคคล", "3"));
                rblContactType.Items.Add(new ListItem("บุคคลธรรมดา", "4"));
                rblContactType.Items[0].Selected = true;
            }
        }

        private void LoadRootNodes(RadTreeView treeView, TreeNodeExpandMode expandMode)
        {
            IList<M_HRM_MAS_Provinces> ProvInfolist = prov.GetList(null);

            foreach (M_HRM_MAS_Provinces info in ProvInfolist)
            {
                RadTreeNode node = new RadTreeNode();
                node.Text = info.prov_name;
                node.Value = info.prov_seq.ToString();
                node.ExpandMode = expandMode;
                node.Category = "Level0";
                treeView.Nodes.Add(node);
            }
        }

        private void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode)
        {
            switch (e.Node.Category)
            {
                case "Level0":
                    IList<M_HRM_MAS_Amphurs> AmpInfolist = amp.GetList(e.Node.Value);

                    foreach (M_HRM_MAS_Amphurs info in AmpInfolist)
                    {
                        RadTreeNode node = new RadTreeNode();
                        node.Text = info.amp_name;
                        node.Value = info.amp_seq.ToString();
                        node.ExpandMode = expandMode;
                        node.Category = "Level1";
                        e.Node.Nodes.Add(node);
                    }

                    e.Node.Expanded = true;
                    break;
                case "Level1":
                    IList<M_HRM_MAS_Districts> DisInfolist = dis.GetList(e.Node.Value);

                    foreach (M_HRM_MAS_Districts info in DisInfolist)
                    {
                        RadTreeNode node = new RadTreeNode();
                        node.Text = info.district_name;
                        node.Value = info.district_seq.ToString();
                        node.Category = "Level2";
                        e.Node.Nodes.Add(node);
                    }

                    e.Node.Expanded = true;
                    break;
            }
        }

        protected bool CheckData1()
        {
            bool bOK = true;
            string strContactName = txtContactName.Text;
            string strTaxID = txtTaxID.Text;
            string strCitizenID = txtCitizenID.Text;
            string strContactType = rblContactType.SelectedValue;

            if (strContactName.Length == 0)
            {
                bOK = false;
                lblError.Text = "กรุณาใส่ข้อมูล [ชื่อเจ้าหนี้ / ลูกหนี้]";
            }
            //else if (strContactType == "1")//ส่วนราชการ
            //{
                
            //}
            //else if (strContactType == "2")//รัฐวิสาหกิจ
            //{

            //}
            else if ((strContactType == "1" || strContactType == "2" || strContactType == "3")
                && strTaxID.Length == 0)//นิติบุคคล
            {
                bOK = false;
                lblError.Text = "กรุณาใส่ข้อมูล [เลขประจำตัวผู้เสียภาษี]";
            }
            else if (strContactType == "4" && strCitizenID.Length == 0)//บุคคลธรรมดา
            {
                bOK = false;
                lblError.Text = "กรุณาใส่ข้อมูล [เลขประจำตัวประชาชน]";
            }

            return bOK;
        }

        protected void UpdateUI1(string strCommand)
        {
            switch (strCommand)
            {
                case "ViewAll":
                case "Insert":
                case "Update":
                    cmdViewAll1.Visible = false;
                    cmdAddNew1.Visible = true;
                    cmdEdit1.Visible = true;
                    cmdDelete1.Visible = true;
                    cmdInsert1.Visible = false;
                    cmdUpdate1.Visible = false;

                    PanelRadGrid1.Visible = true;
                    PanelEdit1.Visible = false;
                    break;
                case "AddNew":
                    cmdViewAll1.Visible = true;
                    cmdAddNew1.Visible = false;
                    cmdEdit1.Visible = false;
                    cmdDelete1.Visible = false;
                    cmdInsert1.Visible = true;
                    cmdUpdate1.Visible = false;

                    PanelRadGrid1.Visible = false;
                    PanelEdit1.Visible = true;
                    break;
                case "Edit":
                    cmdViewAll1.Visible = true;
                    cmdAddNew1.Visible = false;
                    cmdEdit1.Visible = false;
                    cmdDelete1.Visible = false;
                    cmdInsert1.Visible = false;
                    cmdUpdate1.Visible = true;

                    PanelRadGrid1.Visible = false;
                    PanelEdit1.Visible = true;
                    break;
            }
        }

        //protected void UpdateUI2(string strCommand)
        //{
        //    switch (strCommand)
        //    {
        //        case "ViewAll":
        //        case "Insert":
        //        case "Update":
        //            cmdViewAll2.Visible = false;
        //            cmdAddNew2.Visible = true;
        //            cmdEdit2.Visible = true;
        //            cmdDelete2.Visible = true;
        //            cmdInsert2.Visible = false;
        //            cmdUpdate2.Visible = false;

        //            PanelRadGrid2.Visible = true;
        //            PanelEdit2.Visible = false;
        //            PanelControl1.Enabled = true;
        //            PanelRadGrid1.Enabled = true;
        //            break;
        //        case "AddNew":
        //            cmdViewAll2.Visible = true;
        //            cmdAddNew2.Visible = false;
        //            cmdEdit2.Visible = false;
        //            cmdDelete2.Visible = false;
        //            cmdInsert2.Visible = true;
        //            cmdUpdate2.Visible = false;

        //            PanelRadGrid2.Visible = false;
        //            PanelEdit2.Visible = true;
        //            PanelControl1.Enabled = false;
        //            PanelRadGrid1.Enabled = false;
        //            break;
        //        case "Edit":
        //            cmdViewAll2.Visible = true;
        //            cmdAddNew2.Visible = false;
        //            cmdEdit2.Visible = false;
        //            cmdDelete2.Visible = false;
        //            cmdInsert2.Visible = false;
        //            cmdUpdate2.Visible = true;

        //            PanelRadGrid2.Visible = false;
        //            PanelEdit2.Visible = true;
        //            PanelControl1.Enabled = false;
        //            PanelRadGrid1.Enabled = false;
        //            break;
        //    }
        //}

        protected void ClearControl1()
        {
            lblContactSeq.Text = "";
            txtContactName.Text = "";
            txtTaxID.Text = "";
            txtCitizenID.Text = "";
            txtAddress.Text = "";
            ddlDistrictSeq.SelectedIndex = 0;
            ddlCountrySeq.SelectedIndex = 0;
            txtPostalCode.Text = "";
            txtTel.Text = "";
            txtFax.Text = "";
            txtEmail.Text = "";
            rblContactStatus.SelectedIndex = 0;
        }

        //protected void ClearControl2()
        //{
        //    lblContactSeq2.Text = "";
        //    lblContactPersonSeq.Text = "";
        //    txtContactPersonName.Text = "";
        //    rblContactPersonStatus.SelectedIndex = 0;
        //}

        //============================ control events ==============================

        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick" && e.Item is GridDataItem)
            {
                e.Item.Selected = true;
                string strContactSeq = e.Item.OwnerTableView.Items[e.Item.ItemIndex]["contact_seq"].Text;
                Session["ContactSeq"] = strContactSeq;
                //RadGrid2.Enabled = true;
                //PanelControl2.Enabled = true;
                //LoadRadGrid2(strContactSeq);
            }
        }

        //protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)
        //{
        //    if (e.CommandName == "Sort" || e.CommandName == "Filter")
        //    {
        //        LoadRadGrid2(RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text);
        //    }
        //}

        protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (!e.IsFromDetailTable)
            {
                LoadRadGrid1();
            }
        }

        protected void cmdViewAll1_Click(object sender, EventArgs e)
        {
            UpdateUI1("ViewAll");
            ClearControl1();
        }

        protected void cmdAddNew1_Click(object sender, EventArgs e)
        {
            LoadDDLCountrySeq();
            rblContactType_SelectedIndexChanged(null, null);

            UpdateUI1("AddNew");
        }

        protected void cmdEdit1_Click(object sender, EventArgs e)
        {
            if (RadGrid1.SelectedItems.Count > 0)
            {
                UpdateUI1("Edit");

                LoadDDLCountrySeq();

                string strContactSeq = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text;
                string strContactName = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_name"].Text;
                string strTaxID = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["tax_id"].Text;
                string strCitizenID = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["citizen_id"].Text;
                string strContactType = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_type"].Text;
                //string strIsJuristic = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["is_juristic"].Text;
                string strTaxDeduct = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["tax_deduct"].Text;
                string strAddress = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["address"].Text;
                string strDistrictSeq = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["district_seq"].Text;
                string strDistrictText = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["district_text"].Text;
                string strCountrySeq = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["country_seq"].Text;
                string strPostalCode = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["postal_code"].Text;
                string strTel = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["tel"].Text;
                string strFax = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["fax"].Text;
                string strEmail = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["email"].Text;
                string strContactStatus = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_status"].Text;

                lblContactSeq.Text = main.WebString(strContactSeq);
                txtContactName.Text = main.WebString(strContactName);
                txtTaxID.Text = main.WebString(strTaxID);
                txtCitizenID.Text = main.WebString(strCitizenID);

                strContactType = main.WebString(strContactType);
                rblContactTypeGroup.SelectedValue = (strContactType == "1" || strContactType == "2" ? "1" : "2");
                LoadRBLContactType();
                rblContactType.SelectedValue = strContactType;

                rblTaxDeduct.SelectedValue = main.WebString(strTaxDeduct);
                txtAddress.Text = main.WebString(strAddress);;

                ddlDistrictSeq.Text = main.WebString(strDistrictText);
                txtDistrictSeq.Text = main.WebString(strDistrictSeq);
                ddlCountrySeq.SelectedValue = main.WebString(strCountrySeq);
                txtPostalCode.Text = main.WebString(strPostalCode);
                txtTel.Text = main.WebString(strTel);
                txtFax.Text = main.WebString(strFax);
                txtEmail.Text = main.WebString(strEmail);
                rblContactStatus.SelectedValue = main.WebString(strContactStatus);
            }
            else
            {
            }
        }

        protected void cmdDelete1_Click(object sender, EventArgs e)
        {
            if (RadGrid1.SelectedItems.Count > 0)
            {
                M_FIM_MAS_Contacts info = new M_FIM_MAS_Contacts();
                string strContactSeq = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text;
                string strUserID = Session["EmpSeq"].ToString();
                DateTime dtNow = DateTime.Now;

                info.contact_seq = Convert.ToInt32(strContactSeq);
                info.updated_by = main.ConvertNullInt(strUserID);
                info.updated_when = main.ConvertNullDateTime(dtNow);

                con.Delete(info);

                LoadRadGrid1();
                RadGrid1.DataBind();
            }
        }

        protected void cmdInsert1_Click(object sender, EventArgs e)
        {
            if (!CheckData1())
            {
                return;
            }

            M_FIM_MAS_Contacts info = new M_FIM_MAS_Contacts();
            string strContactName = txtContactName.Text;
            string strTaxID = txtTaxID.Text;
            string strCitizenID = txtCitizenID.Text;
            string strContactType = rblContactType.SelectedValue;
            string strTaxDeduct = rblTaxDeduct.SelectedValue;
            string strAddress = txtAddress.Text;
            string strDistrictSeq = (ddlDistrictSeq.Text.Length > 0 ? txtDistrictSeq.Text : "");
            string strCountrySeq = ddlCountrySeq.SelectedValue;
            string strPostalCode = txtPostalCode.Text;
            string strTel = txtTel.Text;
            string strFax = txtFax.Text;
            string strEmail = txtEmail.Text;
            string strContactStatus = rblContactStatus.SelectedValue;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            info.contact_name = strContactName;
            info.tax_id = strTaxID;
            info.citizen_id = strCitizenID;
            info.contact_type = strContactType;
            info.is_juristic = (strContactType != "4" ? "1" : "0");//นิติบุคคล
            info.tax_deduct = strTaxDeduct;
            info.address = strAddress;
            info.district_seq = main.ConvertNullInt(strDistrictSeq);
            info.country_seq = main.ConvertNullInt(strCountrySeq);
            info.postal_code = strPostalCode;
            info.tel = strTel;
            info.fax = strFax;
            info.email = strEmail;
            info.contact_status = strContactStatus;
            info.created_by = main.ConvertNullInt(strUserID);
            info.created_when = main.ConvertNullDateTime(dtNow);

            con.Insert(info);

            LoadRadGrid1();
            RadGrid1.DataBind();
            UpdateUI1("Insert");
            ClearControl1();
        }

        protected void cmdUpdate1_Click(object sender, EventArgs e)
        {
            if (!CheckData1())
            {
                return;
            }

            M_FIM_MAS_Contacts info = new M_FIM_MAS_Contacts();
            string strContactSeq = lblContactSeq.Text;
            string strContactName = txtContactName.Text;
            string strTaxID = txtTaxID.Text;
            string strCitizenID = txtCitizenID.Text;
            string strContactType = rblContactType.SelectedValue;
            string strTaxDeduct = rblTaxDeduct.SelectedValue;
            string strAddress = txtAddress.Text;
            string strDistrictSeq = (ddlDistrictSeq.Text.Length > 0 ? txtDistrictSeq.Text : "");
            string strCountrySeq = ddlCountrySeq.SelectedValue;
            string strPostalCode = txtPostalCode.Text;
            string strTel = txtTel.Text;
            string strFax = txtFax.Text;
            string strEmail = txtEmail.Text;
            string strContactStatus = rblContactStatus.SelectedValue;
            string strUserID = Session["EmpSeq"].ToString();
            DateTime dtNow = DateTime.Now;

            info.contact_seq = Convert.ToInt32(strContactSeq);
            info.contact_name = strContactName;
            info.tax_id = strTaxID;
            info.citizen_id = strCitizenID;
            info.contact_type = strContactType;
            info.is_juristic = (strContactType != "4" ? "1" : "0");
            info.tax_deduct = strTaxDeduct;
            info.address = strAddress;
            info.district_seq = main.ConvertNullInt(strDistrictSeq);
            info.country_seq = main.ConvertNullInt(strCountrySeq);
            info.postal_code = strPostalCode;
            info.tel = strTel;
            info.fax = strFax;
            info.email = strEmail;
            info.contact_status = strContactStatus;
            info.updated_by = main.ConvertNullInt(strUserID);
            info.updated_when = main.ConvertNullDateTime(dtNow);

            con.Update(info);

            LoadRadGrid1();
            RadGrid1.DataBind();
            UpdateUI1("Update");
            ClearControl1();
        }

        //protected void cmdViewAll2_Click(object sender, EventArgs e)
        //{
        //    UpdateUI2("ViewAll");

        //    ClearControl2();
        //}

        //protected void cmdAddNew2_Click(object sender, EventArgs e)
        //{
        //    UpdateUI2("AddNew");

        //    string strContactSeq = RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text;

        //    lblContactSeq2.Text = strContactSeq;
        //}

        //protected void cmdEdit2_Click(object sender, EventArgs e)
        //{
        //    if (RadGrid2.SelectedItems.Count > 0)
        //    {
        //        UpdateUI2("Edit");

        //        string strContactPersonSeq = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_person_seq"].Text;
        //        string strContactSeq = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_seq"].Text;
        //        string strContactPersonName = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_person_name"].Text;
        //        string strContactPersonPosition = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_person_position"].Text;
        //        string strContactPersonStatus = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_person_status"].Text;

        //        lblContactPersonSeq.Text = main.WebString(strContactPersonSeq);
        //        lblContactSeq2.Text = main.WebString(strContactSeq);
        //        txtContactPersonName.Text = main.WebString(strContactPersonName);
        //        txtContactPersonPosition.Text = main.WebString(strContactPersonPosition);
        //        rblContactPersonStatus.SelectedValue = main.WebString(strContactPersonStatus);
        //    }
        //    else
        //    {
        //    }
        //}

        //protected void cmdDelete2_Click(object sender, EventArgs e)
        //{
        //    M_FIM_MAS_ContactPersons info = new M_FIM_MAS_ContactPersons();
        //    string strPK = RadGrid2.Items[RadGrid2.SelectedItems[0].ItemIndex]["contact_person_seq"].Text;
        //    string strUserID = Session["EmpSeq"].ToString();
        //    DateTime dtNow = DateTime.Now;

        //    info.contact_person_seq = Convert.ToInt32(strPK);
        //    info.updated_by = main.ConvertNullInt(strUserID);
        //    info.updated_when = main.ConvertNullDateTime(dtNow);

        //    per.Delete(info);
        //    LoadRadGrid2(RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text);
        //    RadGrid2.DataBind();
        //}

        //protected void cmdInsert2_Click(object sender, EventArgs e)
        //{
        //    M_FIM_MAS_ContactPersons info = new M_FIM_MAS_ContactPersons();
        //    string strContactSeq = lblContactSeq2.Text;
        //    string strContactPersonName = txtContactPersonName.Text;
        //    string strContactPersonPosition = txtContactPersonPosition.Text;
        //    string strContactPersonStatus = rblContactPersonStatus.SelectedValue;
        //    string strUserID = Session["EmpSeq"].ToString();
        //    DateTime dtNow = DateTime.Now;

        //    info.contact_seq = main.ConvertNullInt(strContactSeq);
        //    info.contact_person_name = strContactPersonName;
        //    info.contact_person_position = strContactPersonPosition;
        //    info.contact_person_status = strContactPersonStatus;
        //    info.created_by = main.ConvertNullInt(strUserID);
        //    info.created_when = main.ConvertNullDateTime(dtNow);

        //    per.Insert(info);

        //    LoadRadGrid2(RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text);
        //    RadGrid2.DataBind();
        //    UpdateUI2("Insert");
        //    ClearControl2();
        //}

        //protected void cmdUpdate2_Click(object sender, EventArgs e)
        //{
        //    M_FIM_MAS_ContactPersons info = new M_FIM_MAS_ContactPersons();
        //    string strContactPersonSeq = lblContactPersonSeq.Text;
        //    string strContactSeq = lblContactSeq2.Text;
        //    string strContactPersonName = txtContactPersonName.Text;
        //    string strContactPersonPosition = txtContactPersonPosition.Text;
        //    string strContactPersonStatus = rblContactPersonStatus.SelectedValue;
        //    string strUserID = Session["EmpSeq"].ToString();
        //    DateTime dtNow = DateTime.Now;

        //    info.contact_person_seq = Convert.ToInt32(strContactPersonSeq);
        //    info.contact_seq = main.ConvertNullInt(strContactSeq);
        //    info.contact_person_name = strContactPersonName;
        //    info.contact_person_position = strContactPersonPosition;
        //    info.contact_person_status = strContactPersonStatus;
        //    info.updated_by = main.ConvertNullInt(strUserID);
        //    info.updated_when = main.ConvertNullDateTime(dtNow);

        //    per.Update(info);

        //    LoadRadGrid2(RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text);
        //    RadGrid2.DataBind();
        //    UpdateUI2("Update");
        //    ClearControl2();
        //}

        protected void CheckCitizenID(object source, ServerValidateEventArgs args)
        {
            //if (!DateTimeX.IsValidDmyDate(args.Value, true))
            //{
            //    args.IsValid = false;
            //}
        }

        protected void CheckTaxID(object source, ServerValidateEventArgs args)
        {
            //if (!DateTimeX.IsValidDmyDate(args.Value, true))
            //{
            //    args.IsValid = false;
            //}
        }

        protected void CheckPostalCode(object source, ServerValidateEventArgs args)
        {
            if (args.Value.Length > 0 && args.Value.Length < 5)
            {
                args.IsValid = false;
            }
        }

        protected void treeDistrictSeq_NodeExpand(object sender, RadTreeNodeEventArgs e)
        {
            PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSideCallBack);
        }

        protected void rblContactTypeGroup_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadRBLContactType();
        }

        protected void rblContactType_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateInputTaxIDAndCitizenID();
        }

        protected void UpdateInputTaxIDAndCitizenID()
        {
            string strContactType = rblContactType.SelectedValue;

            if (strContactType == "4")
            {
                lblStar1.Visible = false;
                lblStar2.Visible = true;
            }
            else
            {
                lblStar1.Visible = true;
                lblStar2.Visible = false;
            }
        }

        //protected void RadGrid2_PageIndexChanged(object source, GridPageChangedEventArgs e)
        //{
        //    LoadRadGrid2(RadGrid1.Items[RadGrid1.SelectedItems[0].ItemIndex]["contact_seq"].Text);
        //}

        //==========================================================================
    }
}
